package com.aidex.biz.service.impl;

import com.aidex.biz.domain.Customer;
import com.aidex.biz.domain.CustomerTest;
import com.aidex.biz.mapper.CustomerTestMapper;
import com.aidex.biz.service.CustomerTestService;
import com.aidex.common.annotation.DataScope;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.common.utils.NumberUtils;
import com.aidex.common.utils.StringUtils;
import com.aidex.common.utils.sql.SqlUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 基础Service业务层处理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-05-23
 */
@Service
@Transactional(readOnly = true)
public class CustomerTestServiceImpl extends BaseServiceImpl<CustomerTestMapper, CustomerTest> implements CustomerTestService {
    private static final Logger log = LoggerFactory.getLogger(CustomerTestServiceImpl.class);

    /**
     * 获取单条数据
     *
     * @param customerTest 基础
     * @return 基础
     */
    @Override
    public CustomerTest get(CustomerTest customerTest) {
        CustomerTest dto = super.get(customerTest);
        return dto;
    }

    /**
     * 获取单条数据
     *
     * @param id 基础id
     * @return 基础
     */
    @Override
    public CustomerTest get(String id) {
        CustomerTest dto = super.get(id);
        return dto;
    }


    /**
     * 查询基础列表
     *
     * @param customerTest 基础
     * @return 基础
     */
    @Override
    @DataScope(userAlias = "a", deptAlias = "a")
    public List<CustomerTest> findList(CustomerTest customerTest) {
        return super.findList(customerTest);
    }

    /**
     * 保存基础
     *
     * @param customerTest
     * @return 结果
     */
    @Override
    public boolean save(CustomerTest customerTest) {
        return super.save(customerTest);
    }


    /**
     * 删除基础信息
     *
     * @param customerTest
     * @return 结果
     */
    @Override
    public boolean remove(CustomerTest customerTest) {
        return super.remove(customerTest);
    }

    /**
     * 批量删除基础
     *
     * @param ids 需要删除的基础ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteCustomerTestByIds(String[] ids) {
        return mapper.deleteCustomerTestByIds(ids);
    }

    /**
     * 获取最大编号
     *
     * @param customerTest 基础
     * @return 结果
     */
    @Override
    public int findMaxSort(CustomerTest customerTest) {
        return NumberUtils.nextOrder(mapper.findMaxSort(customerTest));
    }

    @Transactional(readOnly = false)
    @Override
    public Integer deleteCustomerTestByType(CustomerTest customerTest) {
        return mapper.deleteCustomerTestByType(customerTest);
    }

    @Override
    public PageInfo<Customer> findCustomerTestJoinList(Customer customerTest) {
        PageDomain page = customerTest.getPage();
        Integer pageNum = page.getPageNum();
        Integer pageSize = page.getPageSize();
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
            String orderBy = SqlUtil.escapeOrderBySql(page.getOrderBy());
            Boolean reasonable = page.getReasonable();
            PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
        }
        return new PageInfo(mapper.findCustomerTestJoinList(customerTest));
    }
}

